/**
 * 公共基础接口封装
 */
import request from '../utils/request'

// 获取用户列表
export const getUser = (params) => {
  return request({
    method: 'GET',
    url: '/users',
    params
  })
}

// 根据id获取用户
export const getUserById = (id) => {
  return request({
    method: 'GET',
    url: `/users/${id}`
  })
}

// 编辑用户状态
export const setUserState = (userInfo) => {
  return request({
    method: 'PUT',
    url: `/users/${userInfo.id}/state/${userInfo.mg_state}`,
  })
}

// 添加用户
export const addUser = (data) => {
  return request({
    method: 'POST',
    url: '/users',
    data
  })
}

// 编辑用户信息
export const editUser = (userInfo) => {
  return request({
    method: 'PUT',
    url: `/users/${userInfo.id}`,
    data: {
      email: userInfo.email,
      mobile: userInfo.mobile
    }
  })
}

// 删除用户
export const deleteUser = (id) => {
  return request({
    method: 'DELETE',
    url: `/users/${id}`
  })
}

// 给用户分配角色
export const setRoles = (userInfo) => {
  return request({
    method: 'PUT',
    url: `/users/${userInfo.id}/role`,
    data: {
      rid: userInfo.roleId+'',
    }
  })
}

